package controller;

import java.io.Serializable;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class HealthController implements Serializable {
	
	@RequestMapping("/toInfo.do")
	public String juge() {
		System.out.println("前往基本信息录入页面......");
		return "info";
	}
	
	@RequestMapping("/toJudge.do")
	public String toJudge(HealthBean hb, HttpServletRequest request) {
		System.out.println("读取数据，并且进行业务逻辑处理，然后将数据响应到页面......");
		Double weight = Double.parseDouble(hb.getWeight());
		Double height = Double.parseDouble(hb.getHeight());
		Double result = weight / height / height;
		String judge = null;
		if(result >= 32) {
			judge = "非常胖";
		}
		if(result >= 27 && result < 32) {
			judge = "肥胖";
		}
		if(result >= 24 && result < 27) {
			judge = "偏重";
		}
		if(result >= 18.5 && result < 24) {
			judge = "正常";
		}
		if(result < 18.5) {
			judge = "偏轻";
		}
		request.setAttribute("judge", judge);
		request.setAttribute("result", result);
		return "result";
	}
	
}
